package com.calendar.MaiDong;

import android.view.View;

import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.uimanager.SimpleViewManager;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.annotations.ReactProp;

import java.util.Map;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class RNCalendarView extends SimpleViewManager{
    CalendarView calendarView;

    public static final int LAST_MONTH = 1;
    public static final int BACK_TO_TODAY = 2;
    public static final int SPECIFIED_DATE = 3;
    public static final int NEXT_MONTH = 4;
    public static final int WEEK = 5;
    public static final int MONTH = 6;

    @Override
    public String getName(){
        return "RNCalendarView";
    }

    @Override
    protected CalendarView createViewInstance(final ThemedReactContext reactContext){
        calendarView = new CalendarView(reactContext);
        return calendarView;
    }

//    给RN传值使用的方法
    @Nullable
    @Override
    public Map<String, Object> getExportedCustomDirectEventTypeConstants() {
        MapBuilder.Builder<String,Object> builder = MapBuilder.builder();
        builder.put("ClickDate",MapBuilder.of("registrationName","onClickDate"));
        builder.put("CalendarHeight",MapBuilder.of("registrationName","onChangeCalendarHeight"));
        return builder.build();
    }

//    RN上的监听
    @Nullable
    @Override
    public Map<String, Integer> getCommandsMap() {
        return MapBuilder.of(
                "lastMonth",LAST_MONTH,
                "toToday",BACK_TO_TODAY,
                "specifiedDate",SPECIFIED_DATE,
                "nextMonth",NEXT_MONTH,
                "week",WEEK,
                "month",MONTH
                );
    }

//    接受RN上的监听
    @Override
    public void receiveCommand(@Nonnull View root, int commandId, @Nullable ReadableArray args) {
        switch (commandId){
            case LAST_MONTH:
                calendarView.jumpToLastMonth();
                break;
            case BACK_TO_TODAY:
                calendarView.backToToday();
                break;
            case SPECIFIED_DATE:
                calendarView.jumpToSpecifiedDate(args.getString(0));
                break;
            case NEXT_MONTH:
                calendarView.jumpToNextMonth();
                break;
            case WEEK:
                calendarView.showWeek();
                break;
            case MONTH:
                calendarView.showMonth();
                break;
                default:
                    break;
        }
    }

    //    需要选中的日期数组
    @ReactProp(name="dateArray")
    public void setDateArray(CalendarView calendarView, ReadableArray dateArray){
        calendarView.setDateArray(dateArray);
    }

    //    日历长
    @ReactProp(name="width")
    public void setWidth(CalendarView calendarView, float width){
        calendarView.setWidth(width);
    }

    //    日历高
    @ReactProp(name="height")
    public void setHeight(CalendarView calendarView, float height){
        calendarView.setHeight(height);
    }

    //    当天的颜色
    @ReactProp(name="todayColor")
    public void setTodayColor(CalendarView calendarView, String todayColor){
        calendarView.setTodayColor(todayColor);
    }

    //    选中的颜色
    @ReactProp(name="selectionColor")
    public void setSelectionColor(CalendarView calendarView, String selectionColor){
        calendarView.setSelectionColor(selectionColor);
    }

    //    含有事件的日期默认颜色
    @ReactProp(name="eventDefaultColor")
    public void setEventDefaultColor(CalendarView calendarView, String eventDefaultColor){
        calendarView.setEventDefaultColor(eventDefaultColor);
    }

    //    星期几的颜色
    @ReactProp(name="weekdayTextColor")
    public void setWeekdayTextColor(CalendarView calendarView, String weekdayTextColor){
        calendarView.setWeekdayTextColor(weekdayTextColor);
    }

    //    头部标题颜色
    @ReactProp(name="headerTitleColor")
    public void setHeaderTitleColor(CalendarView calendarView, String headerTitleColor){
        calendarView.setHeaderTitleColor(headerTitleColor);
    }

    //    日历背景颜色
    @ReactProp(name="calendarBackgroundColor")
    public void setCalendarBackgroundColor(CalendarView calendarView, String calendarBackgroundColor){
        calendarView.setCalendarBackgroundColor(calendarBackgroundColor);
    }

    //    标题默认颜色
    @ReactProp(name="titleDefaultColor")
    public void setTitleDefaultColor(CalendarView calendarView, String titleDefaultColor){
        calendarView.setTitleDefaultColor(titleDefaultColor);
    }

    //    是否显示阴历
    @ReactProp(name="showLunar")
    public void setShowLunar(CalendarView calendarView, boolean showLunar){
        calendarView.setShowLunar(showLunar);
    }

    //    是否是中文
    @ReactProp(name="chinese")
    public void setChinese(CalendarView calendarView, boolean chinese){
        calendarView.setChinese(chinese);
    }

    //    是否显示事件
    @ReactProp(name="showEvent")
    public void setShowEvent(CalendarView calendarView, boolean showEvent){
        calendarView.setShowEvent(showEvent);
    }

    //    是否多选
    @ReactProp(name="allowsMultipleSelection")
    public void setAllowsMultipleSelection(CalendarView calendarView, boolean allowsMultipleSelection){
        calendarView.setAllowsMultipleSelection(allowsMultipleSelection);
    }

    //    是否显示正方形
    @ReactProp(name="square")
    public void setSquare(CalendarView calendarView, boolean square){
        calendarView.setSquare(square);
    }

    //    是否显示正方形
    @ReactProp(name="showHoliday")
    public void setShowHoliday(CalendarView calendarView, boolean showHoliday){
        calendarView.setShowHoliday(showHoliday);
    }

    //    最小和最大日期
    @ReactProp(name="minAndMaxDate")
    public void setMinAndMaxDate(CalendarView calendarView, ReadableArray minAndMaxDate){
        calendarView.setMinAndMaxDate(minAndMaxDate);
    }
}
